#pragma once
#include"HashBucket.h"

namespace hxs
{
	template<class K, class V, class Hash = HashFunc<K>>
	class unordered_map
	{
	public:
		class KeyofValue
		{
		public:
			const K& operator()(const pair<K, V>& p)
			{
				return p.first;
			}
		};

		typedef typename HashBucket<K, pair<const K, V>, KeyofValue, Hash>::iterator iterator;
		typedef typename HashBucket<K, pair<const K, V>, KeyofValue, Hash>::const_iterator const_iterator;
		

		pair<iterator, bool> insert(const pair<K, V>& p)
		{
			return _hb.insert(p);
		}

		iterator find(const K& key)
		{
			return _hb.find(key);
		}

		const_iterator find(const K& key) const
		{
			return _hb.find(key);
		}

		size_t erase(const K& key)
		{
			return _hb.erase(key);
		}

		V& operator[](const K& key)
		{
			auto ret = insert({key, V()});
			return ret.first->second;
		}

		iterator begin() 
		{
			return _hb.begin();
		}

		iterator end()
		{
			return _hb.end();
		}

		const_iterator begin() const
		{
			return _hb.begin();
		}

		const_iterator end() const
		{
			return _hb.end();
		}



	private:
		HashBucket<K, pair<const K, V>, KeyofValue, Hash> _hb;
	};
}